package com.esri.core.internal.tasks.a;

import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.EsriServiceException;
import com.esri.core.io.UserCredentials;
import com.esri.core.tasks.geocode.LocatorGeocodeResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class c extends com.esri.core.internal.tasks.d<List<LocatorGeocodeResult>> {
    private static final long serialVersionUID = 1;

    public c(d dVar, String str, UserCredentials userCredentials) {
        this(dVar, str, userCredentials, null);
    }

    public c(d dVar, String str, UserCredentials userCredentials, TaskListener<List<LocatorGeocodeResult>> taskListener) {
        super(dVar, str, userCredentials, taskListener);
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public List<LocatorGeocodeResult> execute() throws Exception {
        JsonParser a = com.esri.core.internal.io.handler.h.a(getServiceURL() + "/find", this.actionInput.generateRequestParams(), getServiceCredentials());
        if (!com.esri.core.internal.util.d.c(a)) {
            throw new EsriServiceException("This response cannot be parsed.");
        }
        ArrayList arrayList = new ArrayList();
        SpatialReference spatialReference = null;
        while (a.nextToken() != JsonToken.END_OBJECT) {
            String currentName = a.getCurrentName();
            a.nextToken();
            if ("locations".equals(currentName)) {
                while (a.nextToken() != JsonToken.END_ARRAY) {
                    LocatorGeocodeResult fromJson = LocatorGeocodeResult.fromJson(a);
                    if (spatialReference != null) {
                        fromJson.setSpatialreference(spatialReference);
                    }
                    arrayList.add(fromJson);
                }
            } else if ("spatialReference".equals(currentName)) {
                spatialReference = SpatialReference.fromJson(a);
                if (!arrayList.isEmpty()) {
                    Iterator it = arrayList.iterator();
                    while (it.hasNext()) {
                        ((LocatorGeocodeResult) it.next()).setSpatialreference(spatialReference);
                    }
                }
            } else {
                a.skipChildren();
            }
        }
        return arrayList;
    }
}
